<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>验证码设置 - {{ system_config.app_name }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4cc9f0;
            --danger-color: #f72585;
            --warning-color: #f8961e;
            --info-color: #4895ef;
            --light-color: #f8f9fa;
            --dark-color: #212529;
            --sidebar-width: 250px;
            --header-height: 60px;
            --transition-speed: 0.3s;
            
            /* 深色模式变量 */
            --dark-bg: #121212;
            --dark-surface: #1e1e1e;
            --dark-card: #2d2d2d;
            --dark-text: #e0e0e0;
            --dark-text-secondary: #aaaaaa;
            --dark-border: #444444;
        }
        
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            transition: background-color var(--transition-speed), color var(--transition-speed);
        }
        
        /* 深色模式 */
        body.dark-mode {
            background-color: var(--dark-bg);
            color: var(--dark-text);
        }
        
        body.dark-mode .admin-header {
            background: linear-gradient(135deg, var(--dark-card), var(--dark-surface));
            border-bottom: 1px solid var(--dark-border);
        }
        
        body.dark-mode .admin-nav {
            background-color: var(--dark-surface);
            border-right: 1px solid var(--dark-border);
        }
        
        body.dark-mode .admin-nav a {
            color: var(--dark-text-secondary);
        }
        
        body.dark-mode .admin-nav a:hover,
        body.dark-mode .admin-nav a.active {
            background-color: var(--dark-card);
            color: var(--dark-text);
        }
        
        body.dark-mode .card {
            background-color: var(--dark-card);
            border: 1px solid var(--dark-border);
        }
        
        body.dark-mode .form-control,
        body.dark-mode .form-select {
            background-color: var(--dark-surface);
            border: 1px solid var(--dark-border);
            color: var(--dark-text);
        }
        
        body.dark-mode .form-control:focus,
        body.dark-mode .form-select:focus {
            background-color: var(--dark-surface);
            border-color: var(--primary-color);
            color: var(--dark-text);
            box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
        }
        
        body.dark-mode .form-control:disabled,
        body.dark-mode .form-select:disabled {
            background-color: #3a3a3a;
        }
        
        body.dark-mode .file-list {
            background-color: var(--dark-card);
            border: 1px solid var(--dark-border);
        }
        
        body.dark-mode .file-item {
            border-bottom: 1px solid var(--dark-border);
        }
        
        body.dark-mode .file-item:last-child {
            border-bottom: none;
        }
        
        body.dark-mode .btn-close {
            filter: invert(1);
        }
        
        /* 复选框样式 */
        .checkbox-container {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .checkbox-container input[type="checkbox"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
        }
        
        .checkbox-container label {
            cursor: pointer;
            user-select: none;
        }
        
        /* 表单样式 */
        .form-control:focus,
        .form-select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
        }
        
        .form-control:disabled,
        .form-select:disabled {
            background-color: #e9ecef;
        }
        
        .form-control[size-limit],
        .form-select[size-limit] {
            max-width: 200px;
        }
        
        /* 头部样式 */
        .admin-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            height: var(--header-height);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .admin-header h1 {
            font-size: 1.5rem;
            font-weight: 600;
            margin: 0;
        }
        
        .header-controls {
            display: flex;
            gap: 15px;
            align-items: center;
        }
        
        .header-controls button {
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: background 0.3s;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        .header-controls button:hover {
            background: rgba(255, 255, 255, 0.3);
        }
        
        /* 导航栏 */
        .admin-nav {
            width: var(--sidebar-width);
            background-color: white;
            position: fixed;
            top: var(--header-height);
            left: 0;
            bottom: 0;
            overflow-y: auto;
            border-right: 1px solid #e0e0e0;
            transition: transform var(--transition-speed);
            z-index: 999;
        }
        
        .admin-nav ul {
            list-style: none;
            padding: 20px 0;
        }
        
        .admin-nav li {
            margin: 5px 0;
        }
        
        .admin-nav a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            text-decoration: none;
            color: #666;
            transition: all 0.3s;
            gap: 10px;
        }
        
        .admin-nav a:hover,
        .admin-nav a.active {
            background-color: #f0f4ff;
            color: var(--primary-color);
            border-left: 4px solid var(--primary-color);
        }
        
        .admin-nav a i {
            font-size: 1.2rem;
            width: 24px;
            text-align: center;
        }
        
        /* 主内容区 */
        .main-content {
            margin-left: var(--sidebar-width);
            margin-top: var(--header-height);
            padding: 30px;
            min-height: calc(100vh - var(--header-height));
        }
        
        /* 卡片网格 */
        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .dashboard-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
            padding: 25px;
            transition: transform 0.3s, box-shadow 0.3s;
        }
        
        body.dark-mode .dashboard-card {
            background-color: var(--dark-card);
        }
        
        .dashboard-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
        }
        
        .dashboard-card h3 {
            margin-top: 0;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .dashboard-card h3 i {
            font-size: 1.5rem;
        }
        
        /* 表单组 */
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        .form-control,
        .form-select {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            transition: border-color 0.3s;
        }
        
        .form-full {
            max-width: 500px;
        }
        
        /* 保存按钮 */
        .btn-save {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 6px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn-save:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
        }
        
        .btn-save:active {
            transform: translateY(0);
        }
        
        .btn-save:disabled {
            opacity: 0.7;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        
        /* 消息提示 */
        .flash-messages {
            position: fixed;
            top: 80px;
            right: 20px;
            z-index: 2000;
            max-width: 400px;
        }
        
        .flash-message {
            padding: 15px 20px;
            border-radius: 6px;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 10px;
            animation: slideIn 0.3s ease-out;
        }
        
        @keyframes slideIn {
            from {
                transform: translateX(100%);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }
        
        .flash-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        body.dark-mode .flash-success {
            background-color: #2d5a35;
            color: #d4edda;
            border: 1px solid #3b7a45;
        }
        
        .flash-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        body.dark-mode .flash-error {
            background-color: #6a2c33;
            color: #f8d7da;
            border: 1px solid #8a3f45;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .admin-nav {
                transform: translateX(-100%);
            }
            
            .admin-nav.active {
                transform: translateX(0);
            }
            
            .main-content {
                margin-left: 0;
                padding: 20px 15px;
            }
            
            .dashboard-grid {
                grid-template-columns: 1fr;
            }
            
            .admin-header {
                padding: 0 15px;
            }
            
            .header-controls {
                gap: 10px;
            }
            
            .form-full {
                max-width: 100%;
            }
        }
        
        @media (max-width: 480px) {
            .admin-header h1 {
                font-size: 1.2rem;
            }
            
            .header-controls button span {
                display: none;
            }
            
            .header-controls button i {
                margin-right: 0;
            }
            
            .dashboard-card {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <!-- 头部 -->
    <header class="admin-header">
        <h1><i class="bi bi-shield-lock"></i> 验证码设置</h1>
        <div class="header-controls">
            <button id="themeToggle" title="切换主题">
                <i class="bi bi-moon"></i>
                <span>深色模式</span>
            </button>
            <button id="backToAdmin" title="返回管理面板">
                <i class="bi bi-arrow-left-circle"></i>
                <span>返回管理</span>
            </button>
        </div>
    </header>
    
    <!-- 导航栏 -->
    <nav class="admin-nav">
        <ul>
            <li><a href="/admin"><i class="bi bi-speedometer2"></i> 仪表盘</a></li>
            <li><a href="/admin/github_clone"><i class="bi bi-github"></i> GitHub克隆</a></li>
            <li><a href="/error_management"><i class="bi bi-exclamation-triangle"></i> 错误页面</a></li>
            <li><a href="/captcha_settings" class="active"><i class="bi bi-shield-lock"></i> 验证码设置</a></li>
        </ul>
    </nav>
    
    <!-- 主内容区 -->
    <main class="main-content">
        <div class="dashboard-grid">
            <div class="dashboard-card">
                <h3><i class="bi bi-shield-lock"></i> 极验验证配置</h3>
                <form id="captchaForm" class="config-form">
                    <div class="form-group">
                        <label for="geetestId">极验ID</label>
                        <input type="text" class="form-control form-full" id="geetestId" name="geetest_id" 
                               value="{{ system_config.geetest_id or '' }}" placeholder="请输入极验ID">
                    </div>
                    
                    <div class="form-group">
                        <label for="geetestKey">极验密钥</label>
                        <input type="password" class="form-control form-full" id="geetestKey" name="geetest_key" 
                               value="{{ system_config.geetest_key or '' }}" placeholder="请输入极验密钥">
                    </div>
                    
                    <div class="form-group">
                        <div class="checkbox-container">
                            <input type="checkbox" id="offlineDownloadEnabled" name="offline_download_enabled"
                                   {% if system_config.offline_download_enabled %}checked{% endif %}>
                            <label for="offlineDownloadEnabled">启用离线下载功能</label>
                        </div>
                    </div>
                    
                    <button type="submit" class="btn-save">
                        <i class="bi bi-save"></i> 保存设置
                    </button>
                </form>
            </div>
        </div>
    </main>
    
    <!-- 消息提示 -->
    <div class="flash-messages" id="flashMessages"></div>
    
    <script>
        // 主题切换
        document.getElementById('themeToggle').addEventListener('click', function() {
            document.body.classList.toggle('dark-mode');
            const icon = this.querySelector('i');
            const text = this.querySelector('span');
            
            if (document.body.classList.contains('dark-mode')) {
                icon.className = 'bi bi-sun';
                text.textContent = '浅色模式';
                localStorage.setItem('theme', 'dark');
            } else {
                icon.className = 'bi bi-moon';
                text.textContent = '深色模式';
                localStorage.setItem('theme', 'light');
            }
        });
        
        // 返回管理面板
        document.getElementById('backToAdmin').addEventListener('click', function() {
            window.location.href = '/admin';
        });
        
        // 表单提交
        document.getElementById('captchaForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const data = Object.fromEntries(formData);
            
            // 发送请求
            fetch('/api/update_config', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(data => {
                if (data.status === 'success') {
                    showMessage('设置已保存', 'success');
                } else {
                    showMessage('保存失败: ' + data.message, 'error');
                }
            })
            .catch(error => {
                showMessage('保存失败: ' + error.message, 'error');
            });
        });
        
        // 显示消息
        function showMessage(message, type) {
            const flashContainer = document.getElementById('flashMessages');
            const messageElement = document.createElement('div');
            messageElement.className = `flash-message flash-${type}`;
            messageElement.innerHTML = `
                <i class="bi ${type === 'success' ? 'bi-check-circle' : 'bi-exclamation-circle'}"></i>
                <span>${message}</span>
                <button class="btn-close" onclick="this.parentElement.remove()"></button>
            `;
            
            flashContainer.appendChild(messageElement);
            
            // 3秒后自动移除
            setTimeout(() => {
                if (messageElement.parentElement) {
                    messageElement.remove();
                }
            }, 3000);
        }
        
        // 页面加载时检查主题
        document.addEventListener('DOMContentLoaded', function() {
            const savedTheme = localStorage.getItem('theme');
            if (savedTheme === 'dark') {
                document.body.classList.add('dark-mode');
                const icon = document.getElementById('themeToggle').querySelector('i');
                const text = document.getElementById('themeToggle').querySelector('span');
                icon.className = 'bi bi-sun';
                text.textContent = '浅色模式';
            }
        });
    </script>
</body>
</html>